home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / GAMES / P_ROBO31 / ASSASSIN.PR < prev    next >
Text File  |  1993-02-28  |  4KB  |  105 lines

  1. (**************************************************************************)
  2. (*                             W A R N I N G                              *)
  3. (*                                                                        *)
  4. (*  This Robot has NOT been designed to take advantage of the advanced    *)
  5. (*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
  6. (**************************************************************************)
  7.  
  8.   PROCEDURE Assassin;
  9.     { Based on a C-Robot by John R. Naleszkiewicz }
  10.  
  11.     { Scanning routine calls itself recursively with successively }
  12.     { smaller scan widths until the opponent is destroyed or lost. }
  13.     { This robot is always moving to a new random point. }
  14.  
  15.     { "Global" variables, can be used by any function or procedure }
  16.  
  17.   VAR
  18.     x, y           : Integer; { traveling toward this location }
  19.     travelCount    : Integer; { change direction every so often }
  20.     Angle          : Integer; { angle of travel for the robot  }
  21.     hitAngle, hitRange : Integer; { used to pin-point opponent     }
  22.     Switch         : Boolean; { scanning increment TRUE = minus, FALSE = plus }
  23.  
  24.     { make sure the robot is moving in the right direction }
  25.     PROCEDURE evade;
  26.     BEGIN
  27.       travelCount := travelCount-1;
  28.       IF ((travelCount = 0) OR (speed < 51)) THEN
  29.         BEGIN
  30.           drive(Angle, 0); {Slow Down}
  31.           x := Random(800)+100;
  32.           y := Random(800)+100;
  33.           Angle := Angle_To(x, y);
  34.           travelCount := 4;
  35.           WHILE (speed > 49) DO {Nothing} ;
  36.           drive(Angle, 100);
  37.         END;
  38.     END; { end of evade }
  39.  
  40.     FUNCTION NextHitAngle(increment : Integer) : Integer;
  41.     BEGIN
  42.       IF Switch THEN
  43.         NextHitAngle := hitAngle+increment
  44.       ELSE
  45.         NextHitAngle := hitAngle-increment;
  46.     END; { end of nextHitAngle }
  47.  
  48.  
  49.     { scan and fire with increaseing resolution until target is lost }
  50.     PROCEDURE find_n_fire(width, missCount : Integer);
  51.       { width: integer ;          scan width }
  52.       { missCount: integer ;      how many scans before reversing direction }
  53.     VAR
  54.       width2         : Integer;
  55.     BEGIN
  56.       IF (width < 2) THEN
  57.         BEGIN
  58.           width := 2;
  59.           evade;
  60.         END;
  61.  
  62.       width2 := width*2;
  63.  
  64.       IF Switch THEN
  65.         hitAngle := hitAngle-width2*2
  66.       ELSE
  67.         hitAngle := hitAngle+width2*2;
  68.  
  69.       hitRange := scan(NextHitAngle(width2), width);
  70.       missCount := missCount-1;
  71.       WHILE ((hitRange = 0) OR (hitRange > 700)) AND (missCount <> 0) DO
  72.         BEGIN
  73.           hitRange := scan(NextHitAngle(width2), width);
  74.           missCount := missCount-1;
  75.         END;
  76.  
  77.       IF hitRange <> 0 THEN
  78.         BEGIN
  79.           cannon(hitAngle, hitRange);
  80.           find_n_fire((width DIV 2), 10);
  81.         END
  82.       ELSE
  83.         BEGIN
  84.           IF (scan(NextHitAngle(13), 10) = 0) THEN
  85.             BEGIN
  86.               Switch := NOT Switch;
  87.               IF Switch
  88.               THEN hitAngle := hitAngle+13
  89.               ELSE hitAngle := hitAngle-13;
  90.             END;
  91.           evade;
  92.         END;
  93.     END; { end of find_n_fire }
  94.  
  95.   BEGIN {Assassin Main}
  96.     hitAngle := 0; { scanning angle }
  97.     Switch := True; { scanning increment direction }
  98.     travelCount := 0; { intialize travel count }
  99.     evade; { make sure movment is in the right direction }
  100.     REPEAT { loop is executed "forever" }
  101.       find_n_fire(8, 23); { find the opponent and shoot }
  102.     UNTIL Dead OR Winner;
  103.   END; { end of Assassin Main }
  104.  
  105.